import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
#驱动程序管理的⾃动化
#创建驱动对象
#打开浏览器
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
time.sleep(3)
#输⼊论坛系统网址：http://127.0.0.1:58080/sign-in.html
driver.get("http://127.0.0.1:58080/sign-in.html")
time.sleep(3)
#每次输入前先清空账号和密码框，确保后面输入的数据不会衔接前面已经输入的数据。
# 测试用例10，,异常登录：正确账号，错误密码
driver.find_element(By.CSS_SELECTOR,"#username").clear()
driver.find_element(By.CSS_SELECTOR,"#password").clear()
driver.find_element(By.CSS_SELECTOR,"#username").send_keys("ke11")
driver.find_element(By.CSS_SELECTOR,"#password").send_keys("1")
driver.find_element(By.CSS_SELECTOR,"#submit").click()
time.sleep(3)
#每次输入前先清空账号和密码框，确保后面输入的数据不会衔接前面已经输入的数据。
# 测试用例11，,异常登录：错误账号，正确密码
driver.find_element(By.CSS_SELECTOR,"#username").clear()
driver.find_element(By.CSS_SELECTOR,"#password").clear()
driver.find_element(By.CSS_SELECTOR,"#username").send_keys("k")
driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
driver.find_element(By.CSS_SELECTOR,"#submit").click()
time.sleep(3)
#每次输入前先清空账号和密码框，确保后面输入的数据不会衔接前面已经输入的数据。
# 测试用例12，,异常登录：不输入账号和密码
driver.find_element(By.CSS_SELECTOR,"#username").clear()
driver.find_element(By.CSS_SELECTOR,"#password").clear()
driver.find_element(By.CSS_SELECTOR,"#username").send_keys("")
driver.find_element(By.CSS_SELECTOR,"#password").send_keys("")
driver.find_element(By.CSS_SELECTOR,"#submit").click()
time.sleep(3)
#每次输入前先清空账号和密码框，确保后面输入的数据不会衔接前面已经输入的数据。
# 测试用例13，,异常登录：输入正确账号，不输入密码
driver.find_element(By.CSS_SELECTOR,"#username").clear()
driver.find_element(By.CSS_SELECTOR,"#password").clear()
driver.find_element(By.CSS_SELECTOR,"#username").send_keys("ke11")
driver.find_element(By.CSS_SELECTOR,"#password").send_keys("")
driver.find_element(By.CSS_SELECTOR,"#submit").click()
time.sleep(3)
#每次输入前先清空账号和密码框，确保后面输入的数据不会衔接前面已经输入的数据。
# 测试用例14，,异常登录：不输入正确账号，输入正确密码
driver.find_element(By.CSS_SELECTOR,"#username").clear()
driver.find_element(By.CSS_SELECTOR,"#password").clear()
driver.find_element(By.CSS_SELECTOR,"#username").send_keys("")
driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
driver.find_element(By.CSS_SELECTOR,"#submit").click()
time.sleep(3)

#每次输入前先清空账号和密码框，确保后面输入的数据不会衔接前面已经输入的数据。
#测试用例9，,正常登录
driver.find_element(By.CSS_SELECTOR,"#username").clear()
driver.find_element(By.CSS_SELECTOR,"#password").clear()
driver.find_element(By.CSS_SELECTOR,"#username").send_keys("ke11")
driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
driver.find_element(By.CSS_SELECTOR,"#submit").click()

time.sleep(3)

#关闭浏览器
driver.quit()